package com.mxx.common.generator.convert;

import com.mxx.common.generator.GlobalNameConfig;
import com.mxx.common.utils.Strings;

public class HumpNameConverter implements NameConverter {

    private GlobalNameConfig globalNameConfig;


    public HumpNameConverter(GlobalNameConfig globalNameConfig) {
        this.globalNameConfig = globalNameConfig;
    }

    @Override
    public String tableNameToEntityName(String tableName) {
        String name = Strings.toCamelCase(NameOperator.removeAll(tableName, globalNameConfig.getRemoveClassNamePrefix()
                , globalNameConfig.getRemoveClassNameSuffix()));
        char[] chars = name.toCharArray();
        chars[0] = Character.toUpperCase(chars[0]);
        String entityName = NameOperator.addAll(new String(chars), globalNameConfig.getAddClassNamePrefix(), globalNameConfig.getAddClassNameSuffix());
        return entityName;
    }

    @Override
    public String tableFieldToEntityField(String tableFieldName) {
        String name = Strings.toCamelCase(NameOperator.removeAll(tableFieldName, globalNameConfig.getRemoveClassNamePrefix()
                , globalNameConfig.getRemoveClassNameSuffix()));
        String fieldName = NameOperator.addAll(name, globalNameConfig.getAddFieldNamePrefix(), globalNameConfig.getAddFieldNameSuffix());
        return fieldName;
    }

}
